<template>
  <div>
    <div v-if="!isShowDetail">
      <jxf-titletip :title="title" @refreshPage="refreshFuc"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="采购商账号:" prop="telphone">
            <el-input v-model.trim="searchInfo.telphone" ref="input-telphone" clearable @keyup.enter.native="enterNextInput('enterpriseName')"></el-input>
          </el-form-item>
          <el-form-item label="采购商企业名称:" prop="enterpriseName">
            <el-input v-model.trim="searchInfo.enterpriseName" ref="input-enterpriseName" clearable @keyup.enter.native="enterNextInput('salesmanId')"></el-input>
          </el-form-item>
          <el-form-item label="对接业务员:" prop="salesmanName">
            <el-input v-model.trim="searchInfo.salesmanName" ref="input-salesmanId" clearable @keyup.enter.native="onSearch"></el-input>
          </el-form-item>
          <el-form-item label="审核状态:" prop="status">
            <el-select v-model="searchInfo.status" clearable placeholder="全部">
              <el-option label="待审核" value="0"></el-option>
              <!--<el-option label="审核通过" value="1"></el-option>-->
              <el-option label="审核驳回" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属分公司:" prop="agentId">
            <el-select v-model="searchInfo.agentId" clearable filterable placeholder="全部" @focus="getBranchList">
              <el-option :label="agents.userName" :value="agents.id" v-for="(agents, index) in branchList" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <jxf-Date label="创建时间:" :startTime.sync="searchInfo.createTimeStart" :endTime.sync="searchInfo.createTimeEnd" startTimeProp="createTimeStart" endTimeProp="createTimeEnd"></jxf-Date>
          <jxf-Date label="审核时间:" :startTime.sync="searchInfo.auditTimeStart" :endTime.sync="searchInfo.auditTimeEnd" startTimeProp="auditTimeStart" endTimeProp="auditTimeEnd"></jxf-Date>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportExcel" :loading="isSuccess">导出为Excel</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="status" slot-scope="merchant">
            <div v-if="merchant.row.status == 0">待审核</div>
            <!--<div v-if="merchant.row.status == 1">审核通过</div>-->
            <div v-if="merchant.row.status == 2">审核驳回</div>
          </template>
          <template slot="companyName" slot-scope="supplierInfo">
            <div class="jxf-flex-start" v-if="!supplierInfo.info.isEdit">
              {{supplierInfo.info.value}}
            </div>
            <div class="jxf-flex-start" v-else>
              <el-input v-model="supplierInfo.info.value"></el-input>
            </div>
          </template>
          <template slot="createTime" slot-scope="merchant">
            <div>{{merchant.row.createTime ? FormatDate.timeFormat(merchant.row.createTime) : ""}}</div>
          </template>
          <template slot="auditTime" slot-scope="merchant">
            <div>{{merchant.row.auditTime ? FormatDate.timeFormat(merchant.row.auditTime) : ""}}</div>
          </template>
          <template slot="operation" slot-scope="merchant">
            <el-button type="text" @click="watchDetail('1', merchant.row)" v-if="merchant.row.status === 1 || merchant.row.status === 2">查看详情</el-button>
            <el-button type="text" @click="watchDetail('0', merchant.row)" v-else class="c-red">去审核</el-button>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
    <MerchantReview v-else :title="subTitle" @goBack="goBack" :dataInfo="subDataInfo" @goPrewView="goPrewView" @fresh="fresh"></MerchantReview>
  </div>
</template>

<script>
  import MerchantReview from './components/MerchantReview'
  import FormatDate from '@/assets/js/formatDate'
  export default {
    name: "MerchantAuditList",
    components: { MerchantReview },
    data() {
      return {
        title: "采购商审核列表",
        isShowDetail: false,
        searchInfo: {
          telphone: "",
          enterpriseName: "",
          status: "",
          agentId: "",
          salesmanName: "",
          createTimeStart: "",
          createTimeEnd: "",
          auditTimeStart: "",
          auditTimeEnd: ""
        },
        isSuccess: false,
        subTitle: "",
        subDataInfo: {},
        FormatDate: FormatDate,
        branchList: [],
        dataTable: {
          border:true,
          loading:false,
          hasSelect:false,
          hasOperation:false,
          tr: [
            {
              id: '2',
              minWidth: '100',
              label: '采购商账号',
              fixed: "left",
              prop: 'telphone'
            },
            {
              id: '3',
              minWidth: '140',
              label: '采购商企业名称',
              prop: 'enterpriseName'
            },
            {
              id: '4',
              minWidth: '160',
              label: '所属分公司/地区',
              prop: 'agentName'
            },
            {
              id: '5',
              minWidth: '100',
              label: '对接业务员',
              prop: 'salesmanName'
            },
            {
              id: '6',
              label: '创建时间',
              show: 'template',
              width: '160',
              prop: 'createTime'
            },
            {
              id: '7',
              label: '审核状态',
              show: 'template',
              prop: 'status'
            },
            {
              id: '8',
              label: '审核时间',
              show: 'template',
              width: '160',
              prop: 'auditTime'
            },
            {
              id: '9',
              label: '操作',
              show: 'template',
              minWidth: "60",
              fixed: "right",
              prop: 'operation'
            }
          ],
          operation: [],
          data: []
        },
        pageTotal:0,
        pageSize:10,
        currentPage:1
      }
    },
    methods: {
      fresh() {
        this.getData();
      },
      // 导出
      exportExcel() {
        this.isSuccess = true;
        let data = {
          ...this.searchInfo
        }
        ajax.export(apis.user.exportMerchantReviewExcel, data).then((res) => {
          this.isSuccess = false;
          if(res.code) {
            if(res.code === "10000000") {

            } else {
              this.$message.error(res.message)
            }
          }
        })
      },
      // 返回当前页面
      goPrewView() {
        this.isShowDetail = false
        this.getData()
      },
      getData() {
        this.dataTable.loading = true
        let data = {
          ...this.searchInfo,
          pageNum: this.currentPage,
          pageSize: this.pageSize
        };
        ajax.post(apis.user.merchantAuditing, data).then(res => {
          if(res.code === '10000000') {
            this.dataTable.data = res.data ? res.data.dataList : [];
            this.pageTotal = res.data ? res.data.total : 0;
          } else {
            this.$message.error(res.message)
          }
          this.dataTable.loading = false
        })
      },
      refreshFuc() {
        this.resetForm('searchInfo')
        this.pageSize = 10;
        this.currentPage = 1;
        this.getData()
      },
      // 获取分公司
      getBranchList() {
        let data = {
          userType: '2'
        }
        ajax.post(apis.user.getBranchList, data).then(res => {
          if(res.code == '10000000') {
            this.branchList = res.data.dataList;
          } else {
            this.$message.error(res.message)
          }
        })
      },
      onSearch() {
        this.currentPage = 1
        this.getData()
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      // 切换页面
      currentPageChange(pageNo) {
        this.currentPage = pageNo
        this.getData()
      },
      // 切换页面条数
      pageSizeChange(pageNo) {
        this.pageSize = pageNo
        this.getData()
      },
      // 详情返回上一页
      goBack() {
        this.getData()
        this.isShowDetail = false;
      },
      // 查看详情
      watchDetail(type, obj) {
        switch (type) {
          case '0':
            this.subTitle = "去审核";
            let data = {
              id: obj.id,
              statusNum: 1,
              status: obj.status,
              userId: obj.userId
            };
            ajax.post(apis.user.merchantReview, data).then(res => {
              if(res.code === "10000000") {
                this.subDataInfo = {
                  status: 0,
                  page: 0,
                  accountStatus: null,
                  businessId: res.data.merchantPcVo.businessId,
                  identityCard: {
                    value: res.data.merchantPcVo.identityCardImage ? res.data.merchantPcVo.identityCardImage : "",
                    isEdit: false
                  },
                  license: {
                    value: res.data.merchantPcVo.licenseImage ? res.data.merchantPcVo.licenseImage : "",
                    isEdit: false
                  },
                  cityId: res.data.merchantPcVo.cityId,
                  otherQualification: {
                    value: res.data.merchantPcVo.otherQualification ? res.data.merchantPcVo.otherQualification : "",
                    isEdit: false
                  },
                  id: res.data.merchantPcVo.id,
                  enterpriseAuthId: res.data.merchantPcVo.enterpriseAuthId,
                  logo: res.data.merchantPcVo.logo ? res.data.merchantPcVo.logo : "",
                  reTimeStart: res.data.merchantPcVo.reTimeStart,
                  reTimeEnd: res.data.merchantPcVo.reTimeEnd,
                  identityCardStart: res.data.merchantPcVo.certificateValidity ? res.data.merchantPcVo.certificateValidity.split('-')[0] : "",
                  identityCardEnd: res.data.merchantPcVo.certificateValidity ? res.data.merchantPcVo.certificateValidity.split('-')[1] : "",
                  deliveryIds: res.data.merchantPcVo.deliveryIds,
                  userId: res.data.merchantPcVo.userId,
                  merchantInfo: [
                    {
                      label: "*采购商主体账号",
                      value: res.data.merchantPcVo.telphone,
                      type: "telphone"
                    }, {
                      label: "审核状态",
                      value: res.data.merchantPcVo.status,
                      type: 'status'
                    }, {
                      label: "*企业名称",
                      value: res.data.merchantPcVo.enterpriseName,
                      type: 'enterpriseName',
                      isEdit: false
                    },  {
                      label: "所属分公司",
                      value: res.data.merchantPcVo.agentName,
                      type: "Branch"
                    }, {
                      label: "客服电话",
                      value: res.data.merchantPcVo.contact,
                      type: 'contact',
                      isEdit: false
                    }, {
                      label: "对接业务员",
                      value: res.data.merchantPcVo.salesmanName,
                      type: 'salesmanName'
                    }, {
                      label: "*经营地址",
                      value: res.data.merchantPcVo.detailAdress,
                      type: 'detailAdress',
                      isEdit: false
                    }, {
                      label: "所属渠道商",
                      value: res.data.merchantPcVo.channelDealerName,
                      type: 'channelDealerName'
                    }, {
                      label: "*社会代码",
                      value: res.data.merchantPcVo.creditCode,
                      type: "creditCode",
                      isEdit: false
                    }, {
                      label: "",
                      value: ""
                    }
                  ],
                  otherInfo: [{
                    label: "*注册主体人的名称",
                    value: res.data.merchantPcVo.registrantName,
                    type: "subjectPerson",
                    isEdit: false
                  }, {
                    label: "*注册主体人身份证号码",
                    value: res.data.merchantPcVo.registrantIdNum,
                    type: "registeredIDNumber",
                    isEdit: false
                  }, {
                    label: "*法人名称",
                    value: res.data.merchantPcVo.legalName,
                    type: "legalName",
                    isEdit: false
                  }, {
                    label: "*法人身份证号码",
                    value: res.data.merchantPcVo.idNumber,
                    type: "identityCard",
                    isEdit: false
                  }, {
                    label: "*法人身份证有效期",
                    value: res.data.merchantPcVo.certificateValidity,
                    type: "certificateValidity",
                    isEdit: false
                  }, {
                    label: "入驻时间",
                    value: res.data.merchantPcVo.auditTime,
                    type: "auditTime"
                  }, {
                    label: "南京银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "华夏银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "预留银行卡所属行",
                    value: "",
                    type: "legalIDNumber",
                    isEdit: false
                  }, {
                    label: "银行卡卡号",
                    value: res.data.merchantPcVo.cardNo,
                    type: "cardNo"
                  }],
                  originalinfo: {

                  },

                };
                this.isShowDetail = true;
              } else {
                this.$message.error(res.message)
              }
            })
            break;
          case '1':
            this.subTitle = "查看详情";
            let subData = {
              id: obj.id,
              statusNum: 2,
              status: obj.status,
              userId: obj.userId
            };

            ajax.post(apis.user.merchantReview, subData).then(res => {
              if(res.code === "10000000") {
                this.subDataInfo = {
                  status: 1,
                  page: 0,
                  accountStatus: null,
                  businessId: res.data.merchantPcVo.businessId,
                  identityCard: {
                    value: res.data.merchantPcVo.identityCardImage ? res.data.merchantPcVo.identityCardImage : "",
                    isEdit: false
                  },
                  license: {
                    value: res.data.merchantPcVo.licenseImage ? res.data.merchantPcVo.licenseImage : "",
                    isEdit: false
                  },
                  cityId: res.data.merchantPcVo.cityId,
                  otherQualification: {
                    value: res.data.merchantPcVo.otherQualification ? res.data.merchantPcVo.otherQualification : "",
                    isEdit: false
                  },
                  id: res.data.merchantPcVo.id,
                  enterpriseAuthId: res.data.merchantPcVo.enterpriseAuthId,
                  logo: res.data.merchantPcVo.logo ? res.data.merchantPcVo.logo : "",
                  reTimeStart: res.data.merchantPcVo.reTimeStart,
                  reTimeEnd: res.data.merchantPcVo.reTimeEnd,
                  identityCardStart: res.data.merchantPcVo.certificateValidity ? res.data.merchantPcVo.certificateValidity.split('-')[0] : "",
                  identityCardEnd: res.data.merchantPcVo.certificateValidity ? res.data.merchantPcVo.certificateValidity.split('-')[1] : "",
                  deliveryIds: res.data.merchantPcVo.deliveryIds,
                  userId: res.data.merchantPcVo.userId,
                  merchantInfo: [
                    {
                      label: "*采购商主体账号",
                      value: res.data.merchantPcVo.telphone,
                      type: "telphone"
                    }, {
                      label: "审核状态",
                      value: res.data.merchantPcVo.status,
                      type: 'status'
                    }, {
                      label: "*企业名称",
                      value: res.data.merchantPcVo.enterpriseName,
                      type: 'enterpriseName'
                    },  {
                      label: "所属分公司",
                      value: res.data.merchantPcVo.agentName,
                      type: "Branch"
                    }, {
                      label: "客服电话",
                      value: res.data.merchantPcVo.contact,
                      type: 'contact'
                    }, {
                      label: "对接业务员",
                      value: res.data.merchantPcVo.salesmanName,
                      type: 'salesmanName'
                    }, {
                      label: "*经营地址",
                      value: res.data.merchantPcVo.detailAdress,
                      type: 'detailAdress'
                    }, {
                      label: "所属渠道商",
                      value: res.data.merchantPcVo.channelDealerName,
                      type: 'channelDealerName'
                    }, {
                      label: "*社会代码",
                      value: res.data.merchantPcVo.creditCode,
                      type: "creditCode"
                    }, {
                      label: "",
                      value: ""
                    }
                  ],
                  recording: [
                    {
                      label: "审核人",
                      value: res.data.supplyAuditPcVo.userName,
                      type: "userName"
                    }, {
                      label: "审核时间",
                      value: res.data.supplyAuditPcVo.createTime,
                      type: "createTime"
                    }, {
                      label: "审核结果",
                      value: res.data.supplyAuditPcVo.result,
                      type: "result"
                    }, {
                      label: "审核备注",
                      value: res.data.supplyAuditPcVo.content,
                      type: "content"
                    }
                  ],
                  otherInfo: [{
                    label: "*注册主体人的名称",
                    value: res.data.merchantPcVo.registrantName,
                    type: "subjectPerson",
                    isEdit: false
                  }, {
                    label: "*注册主体人身份证号码",
                    value: res.data.merchantPcVo.registrantIdNum,
                    type: "registeredIDNumber"
                  }, {
                    label: "*法人名称",
                    value: res.data.merchantPcVo.legalName,
                    type: "legalName"
                  }, {
                    label: "*法人身份证号码",
                    value: res.data.merchantPcVo.idNumber,
                    type: "identityCard"
                  }, {
                    label: "*法人身份证有效期",
                    value: res.data.merchantPcVo.certificateValidity,
                    type: "certificateValidity"
                  }, {
                    label: "入驻时间",
                    value: res.data.merchantPcVo.auditTime,
                    type: "auditTime"
                  }, {
                    label: "南京银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "华夏银行子账号",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "预留银行卡所属行",
                    value: "",
                    type: "legalIDNumber"
                  }, {
                    label: "银行卡卡号",
                    value: res.data.merchantPcVo.cardNo,
                    type: "cardNo"
                  }],
                  originalinfo: {

                  },

                };
                this.isShowDetail = true;
              } else {
                this.$message.error(res.message)
              }
            })
            break;
          default:
            return;
        }
      }
    },
    created() {
      this.onSearch()
    }
  }
</script>

<style lang="scss" scoped>

</style>
